//
// Created by Administrator on 2021/10/20.
//

#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

class Solution {
public:
    int countGoodRectangles(vector<vector<int>> &rectangles) {
        unordered_map<int, int> counter;
        int maxSize = 0;
        for (auto &rectangle : rectangles) {
            int less = min(rectangle[0], rectangle[1]); // 两条边中更短的
            counter[less]++;
            maxSize = max(maxSize, less); // 记录最大值
        }
        return counter[maxSize];
    }

    int countGoodRectangles2(vector<vector<int>> &rectangles) {
        // 贪心
        int maxSize = 0, counter = 0;
        for (auto &x:rectangles) {
            int less = min(x[0], x[1]);
            if (less > maxSize) {
                maxSize = less;
                counter = 1;
            }
            else if (less == maxSize)
                ++counter;
        }
        return counter;
    }
};

int main() {
    vector<vector<int>> rectangles{{5,  8},
                                   {3,  9},
                                   {5,  12},
                                   {16, 5}};
    Solution solution;
    cout << solution.countGoodRectangles2(rectangles) << endl;
    return 0;
}